using System.ComponentModel.DataAnnotations.Schema;
using System.Data.Entity.ModelConfiguration;

namespace Viettel.VOFFICE.DAO.Models.Mapping
{
    public class NodeUserMap : EntityTypeConfiguration<NodeUser>
    {
        public NodeUserMap()
        {
            // Primary Key
            this.HasKey(t => new { t.UserId, t.NodeId });

            // Properties
            this.Property(t => t.NodeId)
                .HasDatabaseGeneratedOption(DatabaseGeneratedOption.None);

            // Table & Column Mappings
            this.ToTable("NodeUsers");
            this.Property(t => t.UserId).HasColumnName("UserId");
            this.Property(t => t.NodeId).HasColumnName("NodeId");
            this.Property(t => t.FlowId).HasColumnName("FlowId");
            this.Property(t => t.MainExecutor).HasColumnName("MainExecutor");
            this.Property(t => t.CreatedAt).HasColumnName("CreatedAt");
            this.Property(t => t.UpdatedAt).HasColumnName("UpdatedAt");
            this.Property(t => t.IsActive).HasColumnName("IsActive");
            this.Property(t => t.CreatorId).HasColumnName("CreatorId");

            // Relationships
            this.HasRequired(t => t.aspnet_Users)
                .WithMany(t => t.NodeUsers)
                .HasForeignKey(d => d.UserId);
            this.HasRequired(t => t.Node)
                .WithMany(t => t.NodeUsers)
                .HasForeignKey(d => d.NodeId);

        }
    }
}
